console.log(data);
// 将数据渲染到DEMO结构中
$(function(){
	/*
    IOSWebview方法调用
     */
    function setupWebViewJavascriptBridge(callback) {
      if (window.WebViewJavascriptBridge) {
          return callback(WebViewJavascriptBridge); 
      }
     if (window.WVJBCallbacks) { 
          return window.WVJBCallbacks.push(callback); 
      }

         window.WVJBCallbacks = [callback];
         var WVJBIframe = document.createElement('iframe');
         WVJBIframe.style.display = 'none';
         WVJBIframe.src = 'https://__bridge_loaded__';
         document.documentElement.appendChild(WVJBIframe);

     setTimeout(function() {
         document.documentElement.removeChild(WVJBIframe) }, 0);
      }
     setupWebViewJavascriptBridge(
        function(bridge) {}
     ); 
    //安卓和IOS的跳转逻辑不同，应将所有的a标签的href属性替换为正确的链接
    var browser = {
        versions: function () {
            var u = navigator.userAgent,
                app = navigator.appVersion;
            return { //移动终端浏览器版本信息
                trident: u.indexOf('Trident') > -1, //IE内核
                presto: u.indexOf('Presto') > -1, //opera内核
                webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                mobile: !!u.match(/AppleWebKit.*Mobile/i) || !!u.match(/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/), //是否为移动终端
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
                iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
                iPad: u.indexOf('iPad') > -1, //是否iPad
                webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
            };
        }(),
        language: (navigator.browserLanguage || navigator.language).toLowerCase()
    };

/*
	1  addParameter给不同类型添加参数
	2  system根据系统拼接参数
*/

function addParameter(theType,parameter){

	var jumpUrl = "{goods:0,classify3:0,activity:0,model:0,brand:0}";

	if(theType == "goods"){
		jumpUrl = "{goods:" + parameter +",classify3:0,activity:0,model:0,brand:0}"
	}
	else if(theType == "classify3"){
		jumpUrl = "{goods:0,classify3:" + parameter + ",activity:0,model:0,brand:0}";
	}
	else if(theType == "model"){
		jumpUrl = "{goods:0,classify3:0,activity:0,model:" + parameter + ",brand:0}";
	}
	else{
		jumpUrl = "参数不正确";
	}
	return jumpUrl;
}

function system(thetype,parameter){
	var  system_type       = thetype;
	var  system_parameter  = parameter;
	if (browser.versions.iPhone || browser.versions.iPad || browser.versions.ios){
		theHref = "javascript:WebViewJavascriptBridge.callHandler('ObjC Echo'," +  addParameter(system_type,system_parameter) + ")";
	}
	else{
		theHref = "javascript:demo.startRemove('" + addParameter(system_type,system_parameter) + "')";
	}
	return theHref;
}

/*
	向demo中渲染图片和参数
*/
// 头部banner区域
$('.banner>a').attr("href",system('classify3',763)).children('img').attr('src',data.banner.imgsrc);
// 新手专区
$('.newUser>a').attr("href",system('model',107)).children('img').attr('src',data.newUser.imgsrc);
// 热销推荐
$('.hotRecommend-title img').attr('src',data.hotRecommend.bg);
$('.hotRecommend-container>ul>li:nth-child(1)>a>img').attr('src',data.hotRecommend.parameterImg[0]).parent()
													 .attr('href',system('goods',31230));
$('.hotRecommend-container>ul>li:nth-child(2)>a>img').attr('src',data.hotRecommend.parameterImg[1]).parent()
													 .attr('href',system('goods',3854));	
$('.hotRecommend-container>ul>li:nth-child(3)>a>img').attr('src',data.hotRecommend.parameterImg[2]).parent()
													 .attr('href',system('goods',34745));
// 美味生鲜
$('.fresh-title img').attr('src',data.fresh.bg);
$('.fresh-container>ul>li:nth-child(1)>a>img').attr('src',data.fresh.parameterImg[0]).parent()
													 .attr('href',system('classify3',363));
$('.fresh-container>ul>li:nth-child(2)>a>img').attr('src',data.fresh.parameterImg[1]).parent()
													 .attr('href',system('classify3',362));	
$('.fresh-container>ul>li:nth-child(3)>a>img').attr('src',data.fresh.parameterImg[2]).parent()
													 .attr('href',system('classify3',364));
// 板块1

var phase1 = data.module1[0].moduleDate,
	phase2 = data.module1[1].moduleDate;

var arrPhase1 = phase1.split('-'),
	arrPhase2 = phase2.split('-');

var nowDate = new Date(),
month = nowDate.getMonth()+1,
date  = nowDate.getDate(),
stringMonth = (month<10?('0'+month):month.toString()),
stringDate  = (date<10?('0'+date):date.toString());
today = (stringMonth + stringDate);

if(arrPhase1[0]<today&&today<arrPhase1[1]){
	// 模块1
	$('.module1-title>img').attr('src',data.module1[0].title);
	$('.module1-container>a:nth-child(1)>img').attr('src',data.module1[0].parameterImg[0]).parent()
								 .attr('href',system('classify3',745));
	$('.module1-container>a:nth-child(2)>img').attr('src',data.module1[0].parameterImg[1]).parent()
								 .attr('href',system('classify3',746));
	$('.module1-container>a:nth-child(3)>img').attr('src',data.module1[0].parameterImg[2]).parent()
								 .attr('href',system('classify3',747));
	$('.module1-container>a:nth-child(4)>img').attr('src',data.module1[0].parameterImg[3]).parent()
								 .attr('href',system('classify3',748));	
	// 模块2
	$('.module2-title>img').attr('src',data.module2[0].title);
	$('.module2-container>a:nth-child(1)>img').attr('src',data.module2[0].parameterImg[0]).parent()
								 .attr('href',system('classify3',749));
	$('.module2-container>a:nth-child(2)>img').attr('src',data.module2[0].parameterImg[1]).parent()
								 .attr('href',system('classify3',0));
	$('.module2-container>a:nth-child(3)>img').attr('src',data.module2[0].parameterImg[2]).parent()
								 .attr('href',system('classify3',750));
							 						 							 							 // 
}
else if(arrPhase2[0]<today&&today<arrPhase2[1]){
	// 模块1
	$('.module1-title>img').attr('src',data.module1[1].title);
	$('.module1-container>a:nth-child(1)>img').attr('src',data.module1[1].parameterImg[0]).parent()
								 .attr('href',system('classify3',0));
	$('.module1-container>a:nth-child(2)>img').attr('src',data.module1[1].parameterImg[1]).parent()
								 .attr('href',system('classify3',0));
	$('.module1-container>a:nth-child(3)>img').attr('src',data.module1[1].parameterImg[2]).parent()
								 .attr('href',system('classify3',0));
	$('.module1-container>a:nth-child(4)>img').attr('src',data.module1[1].parameterImg[3]).parent()
								 .attr('href',system('classify3',0));
	// 模块2
	$('.module2-title>img').attr('src',data.module2[1].title);
	$('.module2-container>a:nth-child(1)>img').attr('src',data.module2[1].parameterImg[0]).parent()
								 .attr('href',system('classify3',749));
	$('.module2-container>a:nth-child(2)>img').attr('src',data.module2[1].parameterImg[1]).parent()
								 .attr('href',system('classify3',0));
	$('.module2-container>a:nth-child(3)>img').attr('src',data.module2[1].parameterImg[2]).parent()
								 .attr('href',system('classify3',750));								 

}




})
